<template>
    <div class="NCcontainer">
        <div class="title">定位 / 最近访问</div>
        <div class="btnSet">
            <span :class="['cityBtn','localBtn']" @click="handleClick(locationCity.name)">
                <van-icon name="location-o" />
                {{locationCity.name}}
            </span>
            <span class="cityBtn" v-for="item in clickCity" @click="handleClick(item)">{{item}}</span>
        </div>
    </div>  
</template>

<script setup>
// CC-- 导入pinia的两个方法
import { storeToRefs } from "pinia";
import { onMounted } from "vue";
import {CStore} from '../../stores/counter'

// CC-- 解构出pinia中存储的数据
const $store = CStore()
const {locationCity,clickCity} = storeToRefs($store)


const $emit = defineEmits(['selectCity'])
// 当城市被点击时的回调
function handleClick(name) {
    $emit('selectCity', name)
}




</script>

<style scoped>
    .NCcontainer {
        margin: 20px;

    }
    .title {
        margin-bottom: 20px;
       
    }

    /* 整个按钮组的样式 */
    .btnSet{
        width: 450px;
    }

    /* 城市按钮的样式 */
    .cityBtn {
        border: 1px solid black;
        padding: 10px 20px;
        margin-right: 10px;
        cursor: pointer;
  
    }

    /* 本地城市按钮的专属样式 */
    .localBtn {
        padding: 10px 10px;
    }
</style>